/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package UserInterface;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Hashtable;

/**
 *
 * @author subx
 */
public class CommandAction implements ActionListener {
    /**
     * Lista de comandos.
     */
    private Hashtable commands;


    /**
     * Construtor.
     */
    public CommandAction(){
        InitCommands();
    }

    /**
     * Determina e executa o comando apropriado.
     * 
     * @param e Evento.
     */
    public void actionPerformed(ActionEvent evt) {
        String command = evt.getActionCommand();
        Command cmd = (Command)commands.get(command);

        if(cmd != null)
            cmd.execute(evt);
    }

    /**
     * Inicializa comandos.
     */
    private void InitCommands() {
        Command cmd;
        commands = new Hashtable();

        cmd = new StartCommand();
        commands.put("start", cmd);
        
        cmd = new ExitCommand();
        commands.put("exit", cmd);

        cmd = new LoadCommand();
        commands.put("load", cmd);

        cmd = new UnloadCommand();
        commands.put("unload", cmd);

        cmd = new AboutCommand();
        commands.put("about", cmd);
    }
}
